package com.woniuxy.woniubook.config;

import com.woniuxy.woniubook.intercepters.PermissionIntercepter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfig  implements WebMvcConfigurer {

    @Autowired
    PermissionIntercepter permissionIntercepter ;

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/demo").setViewName("demo");
        registry.addViewController("/").setViewName("index");
        registry.addViewController("/index.html").setViewName("index");
        registry.addViewController("/login.html").setViewName("login");
        registry.addViewController("/cart.html").setViewName("cart");
        registry.addViewController("/reg.html").setViewName("reg");
        registry.addViewController("/order.html").setViewName("order");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(permissionIntercepter)
                .addPathPatterns("/**")
                .excludePathPatterns("/asserts/**")
                .excludePathPatterns("/user/**","/login.html","/reg.html","/order.html","/error","/user/getAccount")
                .excludePathPatterns("/**/reg/*")
                .excludePathPatterns("/","/index.html")
                .excludePathPatterns("/**/home/*")
                .excludePathPatterns("/book/*");
    }
}
